import { detailList, addshopping } from '@/api'
// 封装的临时游客身份模块 生成一个随机字符串作为游客id
import {getUuidToken} from "@/utils/uuid_token"
// search 模块的小仓库
const state = {
    DetailList: {},
    // 游客的临时身份
    uuid_token:getUuidToken(),
}
const mutations = {
    actdetailList(state, rel) {
        state.DetailList = rel
    }
}
const actions = {
    async disdetailFun({ commit }, skuid) {
        let result = await detailList(skuid)
        commit('actdetailList', result.data)
    },
    // 购物车添加
    async disaddshopping({ commit }, { skuId, skuNum }) {
        let result = await addshopping(skuId, skuNum)
        if(result.code == 200){
            return 'ok'
        }else{
            return Promise.reject(new Error('添加失败'))
        }
    }
}
const getters = {
    // 详情页三联标题
    categoryView() {
        return state.DetailList.categoryView || {}
    },
    // 产品信息
    skuInfo() {
        return state.DetailList.skuInfo || {}
    },
    spuSaleAttrList() {
        return state.DetailList.spuSaleAttrList || []
    }
}
export default {
    state,
    mutations,
    actions,
    getters
}